﻿using System;
using System.Web;
using System.Web.Script.Serialization;
using Easy.Operation;

namespace Easy.Web.Service.Entity
{
    /// <summary>
    /// AddAttribute 的摘要说明
    /// </summary>
    public class AddAttribute : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string json = context.Request["addAttribute"];


            ResultClass rc = new ResultClass();

            try
            {

                JavaScriptSerializer jss = new JavaScriptSerializer();

                AddAttributeClass bu = jss.Deserialize<AddAttributeClass>(json);

                if (EntitySetting_Function.CheckAttributeName(bu.EntityId, bu.name))
                {
                    EntitySetting_Function.AddAttribute(bu);
                    rc.Result = 0;
                    rc.Remark = "";
                }
                else {
                    rc.Result = 1;
                    rc.Remark = "已经存在该名字的字段";
                }
               

            }

            catch (Exception e)
            {
                rc.Result = 1;
                rc.Remark = e.Message;
            }


            context.Response.Write(rc.ToJson());



        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}